var t = require("../../../../@babel/runtime/helpers/toConsumableArray"), e = require("../../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        language: "",
        info: {},
        active: 0,
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        timer: null,
        type: "group",
        is_frequency: 0,
        member: [],
        frequency: 0,
        yhShow: !1,
        group_member_id: null,
        zhpObj: []
    },
    onLoad: function(t) {
        if (t.tag && this.setData({
            active: Number(t.tag)
        }), "zhpGroup" == t.types) {
            this.getDataZhp(this.data.active);
            wx.setNavigationBarTitle({
                title: "我的珍惠拼"
            }), this.setData({
                type: t.types,
                zhpObj: [ "正在拼团", "拼团成功", "拼团失败" ]
            });
        } else this.getData(0);
    },
    zhpYh: function(t) {
        var e = this, o = t.currentTarget.dataset.id;
        this.data.group_member_id = o;
        var r = a.getNetAddresss("plugin.zhp-group-lottery.frontend.goods.validate-barter");
        r += "&group_member_id=" + o, a._getNetWork({
            url: r,
            success: function(t) {
                var a = t.data;
                1 == a.result ? e.setData({
                    barter_order_sn: a.data.barter_order_sn,
                    barter_value: a.data.barter_value,
                    barter_plugin_name: a.data.barter_plugin_name,
                    yhShow: !0
                }) : wx.showToast({
                    title: a.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    submityh: function(t) {
        var e = this, o = this, r = 1 == t ? "plugin.zhp-group-lottery.frontend.goods.sendAction" : "plugin.zhp-group-lottery.frontend.goods.barter-action", i = a.getNetAddresss(r);
        i += "&group_member_id=" + this.data.group_member_id, a._getNetWork({
            url: i,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (e.setData({
                    yhShow: !1
                }), wx.showModal({
                    title: "",
                    content: a.msg,
                    showCancel: !0,
                    success: function(t) {
                        t.confirm ? o.getDataZhp(o.data.active) : t.cancel && console.log("用户点击取消");
                    }
                })) : wx.showToast({
                    title: a.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    cancelyh: function() {
        this.setData({
            yhShow: !1
        });
    },
    zhpSendAction: function(t) {
        var e = this, a = t.currentTarget.dataset.id;
        this.data.group_member_id = a, wx.showModal({
            title: "",
            content: "订单选择发货",
            success: function(t) {
                t.confirm ? e.submityh(1) : t.cancel;
            }
        });
    },
    showPopover: function(t) {
        var a = t.currentTarget.dataset.index, o = this.data.info[a].showPopover;
        this.setData(e({}, "info[" + a + "].showPopover", !o));
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        clearTimeout(this.data.timer);
    },
    onPullDownRefresh: function() {
        this.getData(0);
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : wx.showToast({
            title: "没有更多数据",
            icon: "none"
        });
    },
    onShareAppMessage: function() {},
    onChange: function(t) {
        this.setData({
            timeData: t.detail
        });
    },
    getTimeDifference: function(t) {
        var e = Date.parse(new Date()), a = t < 1e12 ? 1e3 * t : t;
        return a - e > 0 ? a - e : a - e <= 0 ? 0 : void 0;
    },
    getDataZhp: function(t) {
        var e = this, o = this, r = a.getNetAddresss("plugin.zhp-group-lottery.frontend.group-member.get-group-member-list");
        a._getNetWork({
            url: r,
            data: {
                is_win: t
            },
            success: function(t) {
                var a = t.data;
                if (1 == a.result) {
                    o.setData({
                        total_page: a.data.last_page,
                        isLoadMore: !0,
                        info: a.data.data,
                        page: e.data.page
                    });
                    for (var r = 0; r < o.data.info.length; r++) o.data.info[r].timeDifference = o.getTimeDifference(o.data.info[r].lottery_time);
                    o.setData({
                        info: e.data.info
                    });
                } else wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            }
        });
    },
    getData: function(t) {
        var e = this, o = {};
        console.log(t), 0 == t ? o.team_status = 1 : 1 == t ? o.team_status = 2 : 2 == t && (o.team_status = 3);
        var r = a.getNetAddresss(1 == a.globalData.store_alone_temp ? "plugin.store-alone-temp.frontend.fightGroups.fight-groups.get-member-join-teams" : "plugin.fight-groups.frontend.controllers.fight-groups.get-member-join-teams");
        a._getNetWork({
            url: r,
            data: o,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (a.data.data.map(function(t) {
                    var e = new Date(1e3 * t.has_one_team.start_time), a = e.getFullYear() + "-", o = (e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1) + "-", r = e.getDate() + " ", i = e.getHours() + ":", n = e.getMinutes() + ":", s = e.getSeconds() < 10 ? e.getSeconds() + "0" : e.getSeconds();
                    t.has_one_team.start_time = a + o + r + i + n + s;
                }), e.setData({
                    total_page: a.data.last_page,
                    isLoadMore: !0,
                    info: a.data.data,
                    page: a.data.current_page,
                    is_frequency: a.data.is_frequency,
                    member: a.data.member,
                    frequency: a.data.frequency
                }), e.countDown(), e.data.total_page || e.setData({
                    total_page: 0
                })) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            }
        });
    },
    toStore: function(t) {
        var e = t.target.dataset.id || t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageC/o2o/HomeSeller/HomeSeller?store_id=" + e
        });
    },
    gotoOrder: function(t) {
        var e = t.target.dataset.id || t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/member/orderdetail/orderdetail?order_id=" + e + "&orderType=groups"
        });
    },
    goZhpUrl: function(t) {
        var e, o, r = t.currentTarget.dataset.item, i = t.currentTarget.dataset.key;
        if ("detail" == i && wx.navigateTo({
            url: "/packageI/newGroup/zhpgroupDetail/zhpgroupDetail?id=" + r.group_id + "&action=2"
        }), "join" == i && (e = a.getNetAddresss("plugin.zhp-group-lottery.frontend.order.participate-group"), 
        o = {
            group_member_id: r.id
        }, this.joinQuitReq(e, o)), "quit" == i && (e = a.getNetAddresss("plugin.zhp-group-lottery.frontend.group-member.cancel-group-member"), 
        o = {
            group_member_id: r.id
        }, this.joinQuitReq(e, o)), "order" == i) {
            var n = t.currentTarget.dataset.id;
            wx.navigateTo({
                url: "/packageA/member/orderdetail/orderdetail?order_id=" + n + "&orderType=zhpGroup"
            });
        }
        console.log(r);
    },
    joinQuitReq: function(t, e) {
        var o = this;
        a._getNetWork({
            url: t,
            data: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }), o.getDataZhp(o.data.active)) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            }
        });
    },
    cancelTap: function(t) {
        var e = this, o = t.currentTarget.dataset.item.id;
        a._getNetWork({
            url: a.getNetAddresss("plugin.zhp-group-lottery.frontend.group-member.quit-msg"),
            data: {
                id: o
            },
            success: function(t) {
                var a = t.data;
                if (1 == a.result) {
                    var r = a.data.refund_poundage_amount;
                    0 == r ? e.canceT(o, "", !1) : e.canceT(o, r, !0);
                } else wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            }
        });
    },
    canceT: function(t, e, o) {
        var r = this, i = a.getNetAddresss("plugin.zhp-group-lottery.frontend.group-member.quit-group"), n = o ? "退团需要扣除退团手续费￥".concat(e, ",退出该团？") : "退出该团";
        wx.showModal({
            title: n,
            content: "",
            success: function(e) {
                e.confirm ? a._getNetWork({
                    url: i,
                    data: {
                        id: t
                    },
                    success: function(t) {
                        var e = t.data;
                        1 == e.result ? (wx.showToast({
                            title: e.msg,
                            icon: "none",
                            duration: 1e3
                        }), r.getDataZhp(r.data.active)) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                }) : e.cancel;
            }
        });
    },
    gotoGroup: function(t) {
        var e = t.target.dataset.item.team_id || t.currentTarget.dataset.item.team_id, a = t.target.dataset.item.store_id || t.currentTarget.dataset.item.store_id;
        wx.navigateTo({
            url: "/packageB/member/group/GroupDetail/GroupDetail?id=" + e + "&store_id=" + a
        });
    },
    getMoreData: function() {
        var e = this;
        this.setData({
            isLoadMore: !1
        });
        var o = {};
        console.log(this.data.page, this.data.total_page);
        var r = "";
        if ("zhpGroup" == this.data.type ? (0 == this.data.active ? o.is_win = 0 : 1 == this.data.active ? o.is_win = 1 : 2 == this.data.active && (o.is_win = 2), 
        r = "plugin.zhp-group-lottery.frontend.group-member.get-group-member-list") : (0 == this.data.active ? o.team_status = 1 : 1 == this.data.active ? o.team_status = 2 : 2 == this.data.active && (o.team_status = 3), 
        r = "plugin.fight-groups.frontend.controllers.fight-groups.get-member-join-teams"), 
        !(this.data.page >= this.data.total_page)) {
            var i = this.data.page;
            i += 1, this.setData({
                page: i
            }), o.page = this.data.page;
            var n = a.getNetAddresss(r);
            a._getNetWork({
                url: n,
                data: o,
                success: function(a) {
                    e.setData({
                        isLoadMore: !0
                    });
                    var o = a.data;
                    if (1 == o.result) {
                        var r = o.data.data;
                        if ("zhpGroup" == e.data.type) {
                            for (var i = 0; i < e.data.info.length; i++) e.data.info[i].timeDifference = e.getTimeDifference(e.data.info[i].lottery_time);
                            e.setData({
                                info: e.data.info
                            });
                            var n = [].concat(t(e.data.info), t(r));
                            return void e.setData({
                                info: n,
                                page: o.data.current_page
                            });
                        }
                        r.map(function(t) {
                            var e = new Date(1e3 * t.has_one_team.start_time), a = e.getFullYear() + "-", o = (e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1) + "-", r = e.getDate() + " ", i = e.getHours() + ":", n = e.getMinutes() + ":", s = e.getSeconds() < 10 ? e.getSeconds() + "0" : e.getSeconds();
                            t.has_one_team.start_time = a + o + r + i + n + s;
                        });
                        var s = [].concat(t(e.data.info), t(r));
                        e.setData({
                            info: s,
                            page: o.data.current_page
                        });
                    } else {
                        var d = e.data.page;
                        d -= 1, e.setData({
                            page: d,
                            isLoadMore: !1
                        }), wx.showToast({
                            icon: "none",
                            title: o.msg,
                            duration: 1500
                        });
                    }
                }
            });
        }
    },
    changeData: function(t) {
        "zhpGroup" == this.data.type ? (console.log(t.detail.index), this.setData({
            active: t.detail.index,
            info: []
        }), this.getDataZhp(t.detail.index)) : (this.setData({
            active: t.detail.index
        }), this.getData(t.detail.index));
    },
    timeFormat: function(t) {
        return t < 10 ? "0" + t : t;
    },
    countDown: function() {
        var t = this, e = new Date().getTime() / 1e3, a = this.data.info;
        a.forEach(function(a) {
            var o = a.has_one_team.end_time;
            if (o - e > 0) {
                a.isShowtime = !0;
                var r = o - e, i = parseInt(r / 86400), n = parseInt(r % 86400 / 3600), s = parseInt(r % 86400 % 3600 / 60), d = parseInt(r % 86400 % 3600 % 60);
                a.obj = {
                    day: t.timeFormat(i),
                    hou: t.timeFormat(n),
                    min: t.timeFormat(s),
                    sec: t.timeFormat(d)
                };
            } else a.isShowtime = !1;
        }), this.setData({
            info: a
        }), this.data.timer = setTimeout(this.countDown, 1e3);
    }
});